package com.da.web.dorm_into.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.da.web.dorm_into.entity.DormInto;
import com.da.web.dorm_into.entity.IntoParm;
import com.da.web.dorm_into.mapper.DormIntoMapper;
import com.da.web.dorm_into.service.DormIntoService;
import org.springframework.stereotype.Service;

/**
 * @author da
 * @time 2023/12/15 上午 10:12
 */
@Service
public class DormIntoServiceImpl extends ServiceImpl<DormIntoMapper, DormInto> implements DormIntoService {
    @Override
    public IPage<DormInto> pageList(IntoParm parm) {
        IPage<DormInto> page = new Page<>(parm.getCurrentPage(), parm.getPageSize());
        QueryWrapper<DormInto> query = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(parm.getName())) {
            query.lambda().like(DormInto::getName, parm.getName());
        }
        if (StrUtil.isNotEmpty(parm.getUsername())) {
            query.lambda().like(DormInto::getUsername, parm.getUsername());
        }
        //根据时间排序
        query.lambda().orderByDesc(DormInto::getIntoTime);
        return this.page(page, query);
    }
}
